package com.nbgroup.web;

import com.alibaba.fastjson.JSON;
import com.nbgroup.entity.Ichnography;
import com.nbgroup.service.IchnographyService;
import com.nbgroup.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 平面图controller
 * 2018年8月15日, PM 02:34:36
 *
 * @author 姜文
 */
@Controller
@RequestMapping(value = "/ichnography")
public class IchnographyController {

    @Autowired
    private IchnographyService ichnographyService;
    @Autowired
    private FileUtil fileUtil;

    /**
     * 查询全部火灾馆平面图
     * 2018年8月16日, AM 10:56:53
     *
     * @author 姜文
     */
    @RequestMapping("/ichnographyList")
    public String ichnographyList(Map<String, Object> map, Ichnography ichnography) {
        if(ichnography.getFloorId() != null){
            map.put("floorId", ichnography.getFloorId());
        }
        map.put("showUrl", fileUtil.getShowUrl());
        map.put("ichnographyList", ichnographyService.findAllForIchnography(ichnography));
        return "ichnography/ichnography";
    }

    /**
     * 跳转平面图展图一层
     * 2018年8月21日, AM 09:00:23
     *
     * @author 姜文
     */
    @RequestMapping("/ichnographyOne")
    public String ichnographyOne(Map<String, Object> map, Integer ichnographyId) {
        map.put("ichnographyId", ichnographyId);
        return "exhibitionHall/exhibition Hall One";
    }

    /**
     * 跳转平面图展图二层
     * 2018年8月16日, AM 10:56:53
     *
     * @author 姜文
     */
    @RequestMapping("/ichnographyTwo")
    public String ichnographyTwo(Map<String, Object> map, Integer ichnographyId) {
        map.put("ichnographyId", ichnographyId);
        return "exhibitionHall/exhibition Hall Two";
    }

    /**
     * 跳转平面图展图三层
     * 2018年8月21日, AM 09:00:18
     *
     * @author 姜文
     */
    @RequestMapping("/ichnographyThree")
    public String ichnographyThree(Map<String, Object> map, Integer ichnographyId) {
        map.put("ichnographyId", ichnographyId);
        return "exhibitionHall/exhibition Hall Three";
    }

    /**
     * 火灾馆平面图保存
     * 2018年8月16日, AM 10:56:53
     *
     * @author 姜文
     */
    @ResponseBody
    @RequestMapping("/saveIchnography")
    public int saveIchnography(Ichnography ichnography) {
        int result = ichnographyService.saveIchnography(ichnography);
        return result;
    }

    /**
     * 火灾馆平面图修改
     * 2018年8月16日, AM 10:56:53
     *
     * @author 姜文
     */
    @ResponseBody
    @RequestMapping("/updateIchnography")
    public int updateIchnography(Ichnography ichnography) {
        int result = ichnographyService.updateIchnography(ichnography);
        return result;
    }

    /**
     * 火灾馆平面图findOne
     * 2018年8月16日, AM 10:56:53
     *
     * @author 姜文
     */
    @ResponseBody
    @RequestMapping("/findOneForIchnography")
    public Ichnography findOneForIchnography(Integer ichnographyId){
        Ichnography ichnography = ichnographyService.findOneForIchnography(ichnographyId);
        return ichnography;
    }

    /**
     * 火灾馆平面图删除
     * 2018年8月16日, AM 10:56:53
     *
     * @author 姜文
     */
    @ResponseBody
    @RequestMapping("/deleteIchnography")
    public int deleteIchnography(Integer ichnographyId) {
        int result = ichnographyService.deleteIchnography(ichnographyId);
        return result;
    }

    /**
     * 上传图片
     * 2018年8月16日, AM 10:56:53
     *
     * @author 姜文
     */
    @ResponseBody
    @RequestMapping(value = "/getImgFileName", method = RequestMethod.POST)
    public String getImgFileName(@RequestParam("imgFile") MultipartFile imgFile) {
        String imgName = fileUtil.saveFile(imgFile);
        return JSON.toJSONString(imgName);
    }
}
